home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Commodities / ColorSaver / src / ColorTest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-27  |  4.2 KB  |  208 lines

  1. /*
  2.  * ColorTest.c  -- compile with "dcc Colortest.c -o ColorTest"  
  3.  *                            
  4.  *   A totally hacked up version of an old, old program I found
  5.  *   somewhere!  I just needed something quick and dirty that opened
  6.  *   up a window so I could draw some colors in it....
  7.  */
  8.  
  9.  
  10. #include "exec/types.h"
  11. #include "intuition/intuition.h"
  12. #include "graphics/display.h"
  13. #include "graphics/gfxmacros.h"
  14.  
  15. struct IntuitionBase *IntuitionBase;
  16. struct Window *Wind;
  17. struct Screen *Scrn;
  18. struct ViewPort *vpt;
  19. struct RastPort *rp;
  20.  
  21. struct IntuiMessage *mes;
  22.  
  23. #define INTUITION_REV 29
  24.  
  25. #define S_HEIGHT 400
  26. #define S_WIDTH 640
  27. #define S_MODE HIRES|INTERLACE
  28.  
  29. #define DEPTH 3
  30.  
  31. #define NUMCOLORS (1 << DEPTH)
  32.  
  33.  
  34. UWORD colortable[] =
  35.         {
  36.         0x0111, 0x0f33, 0x0555, 0x0777, 0x0999, 0x0bbb,
  37.         0x0ddd, 0x0fff, 0x0000, 0x0f11, 0x0f33,
  38.         0x0f55, 0x0f77, 0x0f99, 0x0fbb, 0x0fff
  39.         };
  40. LONG GfxBase;
  41.  
  42. void main(void)
  43. {
  44.   ULONG flags,iflags,class;
  45.   SHORT x,y,w,h,d,mx,my,boxw,border;
  46.   USHORT code,mode,i;
  47.   UBYTE *title,c0,c1;
  48.   VOID delay_func(),OpenAll(),CreateMes();
  49.   APTR Iadr;
  50.  
  51.  
  52.   
  53.   OpenAll();
  54.  
  55.  
  56. /*  ===== Open a hi-res custom screen */
  57.  
  58.  title="Colorsaver Test Screen ";
  59.  y=0;
  60.  w=S_WIDTH;
  61.  h=S_HEIGHT;
  62.  d=DEPTH;
  63.  c0=0;
  64.  c1=12;
  65.  mode=S_MODE;  /*HIRES|INTERLACE;*/
  66.  
  67.  
  68.  Scrn=(struct Screen *)make_screen(y,w,h,d,c0,c1,mode,title);
  69.  
  70. /*  ===== Open a plain window ===== */
  71.  
  72.  x=y=0;
  73.  w=S_WIDTH;
  74.  h=S_HEIGHT;
  75.  flags=ACTIVATE|WINDOWDRAG|WINDOWCLOSE;
  76.  iflags=CLOSEWINDOW;
  77.  c0=6;
  78.  c1=7;
  79.  Wind=(struct Window *)
  80.           make_window(x,y,w,h,"ColorSaver Test",flags,iflags,c0,c1,Scrn);
  81.  if(Wind) rp = Wind->RPort;
  82.  
  83.  vpt =&(Scrn->ViewPort);
  84.  
  85.  LoadRGB4(vpt,&colortable[0],NUMCOLORS);
  86.  
  87.  border  = 10;
  88.  boxw = (640-(border*2))/NUMCOLORS;
  89.  
  90.  for (i = 0; i< NUMCOLORS; i++)
  91.  {
  92.   SetAPen(rp,i);
  93.   RectFill(rp,(i*boxw)+border,20,(i*boxw)+boxw+border,380);
  94.  }
  95.  
  96. /* ===== Set up an IDCMP Read Loop ===== */
  97.  
  98.     for (;;)
  99.     {
  100.         if ((mes = (struct Message *)GetMsg(Wind->UserPort)) == NULL) {
  101.             Wait(1L << Wind->UserPort->mp_SigBit);
  102.             continue;
  103.         }
  104.         class = mes->Class;
  105.         code = mes->Code;
  106.         mx = mes->MouseX;
  107.         my = mes->MouseY;
  108.         Iadr = mes->IAddress;
  109.         ReplyMsg(mes);
  110.             switch (class) {
  111.  
  112.            case CLOSEWINDOW:   CloseThings();
  113.                                exit(NULL);
  114.                                break;
  115.     
  116.         }
  117.     }
  118. }
  119.  
  120.  
  121. VOID OpenAll()
  122. /*  This function will open any necessary libraries*/
  123. {
  124.  
  125. /*   ====== Open intuition =====*/
  126.  
  127.  IntuitionBase=(struct IntuitionBase *)
  128.             OpenLibrary("intuition.library",INTUITION_REV);
  129.  
  130.  if (IntuitionBase==NULL)
  131.      exit(FALSE);
  132.  
  133.  GfxBase=OpenLibrary("graphics.library",0);
  134.  
  135.  if (GfxBase==NULL)
  136.      exit(FALSE);
  137. }
  138.  
  139.  
  140.  
  141. make_window(x,y,w,h,name,flags,iflags,color0,color1,screen)
  142. SHORT x,y,w,h;
  143. UBYTE *name,color0,color1;
  144. ULONG flags,iflags;
  145. struct Screen *screen;
  146.  
  147. /* This function will initialize the NewWindow structure and open the window */
  148. {
  149.    struct NewWindow NewWindow;
  150.    NewWindow.LeftEdge=x;
  151.    NewWindow.TopEdge=y;
  152.    NewWindow.Width=w;
  153.    NewWindow.Height=h;
  154.    NewWindow.DetailPen=-1;
  155.    NewWindow.BlockPen=-1;
  156.    NewWindow.Title=name;
  157.    NewWindow.Flags=flags;
  158.    NewWindow.IDCMPFlags=iflags;
  159.    NewWindow.Type=CUSTOMSCREEN;
  160.    NewWindow.FirstGadget=NULL;
  161.    NewWindow.CheckMark=NULL;
  162.    NewWindow.Screen=screen;
  163.    NewWindow.BitMap=NULL;
  164.    NewWindow.MinWidth=0;
  165.    NewWindow.MinHeight=0;
  166.    NewWindow.MaxWidth=640;
  167.    NewWindow.MaxHeight=200;
  168.  
  169.    return(OpenWindow(&NewWindow));
  170.    
  171. }
  172.  
  173.  
  174. make_screen(y,w,h,d,color0,color1,mode,name)
  175. SHORT y,w,h,d;
  176. UBYTE color0,color1,*name;
  177. USHORT mode;
  178. {
  179.  struct NewScreen NewScreen;
  180.  
  181.    NewScreen.LeftEdge=0;
  182.    NewScreen.TopEdge=y;
  183.    NewScreen.Width=w;
  184.    NewScreen.Height=h;
  185.    NewScreen.Depth=d;
  186.    NewScreen.DetailPen=color0;
  187.    NewScreen.BlockPen=color1;
  188.    NewScreen.ViewModes=mode;
  189.    NewScreen.Type=CUSTOMSCREEN;
  190.    NewScreen.Font=NULL;
  191.    NewScreen.DefaultTitle=name;
  192.    NewScreen.Gadgets=NULL;
  193.    NewScreen.CustomBitMap=NULL;
  194.   
  195.    return(OpenScreen(&NewScreen));
  196.    
  197. }
  198.  
  199.  
  200. CloseThings()
  201.  
  202. {
  203.     if(IntuitionBase) CloseLibrary(IntuitionBase);
  204.     if(GfxBase)       CloseLibrary(GfxBase);
  205.     if(Wind)          CloseWindow(Wind);
  206.     if(Scrn)          CloseScreen(Scrn);
  207. }
  208.